import request from '../utils/request';
import {ElMessage} from "element-plus";


export const fetchGetData = (url, params) => {
    return request({
        url: '/api' + url,
        method: 'get',
        params: params, // 传递参数
    });
};

export const fetchPostData = async (url: string, params: any, data: any) => {
    try {
        return await request({
            url: '/api' + url,
            method: 'post',
            params: params,
            data: data // 传递参数
        });
    } catch (error) {
        ElMessage.error(error?.message);
        return await Promise.reject();
    }
};


export const exportData = async (url: string, params: any, data: any) => {
    try {
        return await request({
            url: '/api' + url,
            method: 'post',
            params: params,
            responseType: 'blob', // 重要，需要设置为blob
            data: data // 传递参数
        });
    } catch (error) {
        ElMessage.error(error.message);
        return await Promise.reject();
    }
};